<!DOCTYPE html>
<html>
<head>
    <block name="include">
        <include file="Public:header"/>
    </block>
</head>
<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="layui-inline">
                <input type="text" class="layui-input" id="txt">
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-sm" id="txtAdd">
                    新增&nbsp;<i class="layui-icon">&#xe654;</i>
                </button>
            </div>
            <div class="layui-tab">

                <ul class="layui-tab-title">
                    <li
                    <if condition="$tab eq 1">class="layui-this"</if>
                    >单字列表</li>
                    <li
                    <if condition="$tab eq 2">class="layui-this"</if>
                    >双字列表</li>
                    <li
                    <if condition="$tab eq 3">class="layui-this"</if>
                    >其他列表</li>
                </ul>
                <style>
                    .nametxt, .nametxt2, .nametxt3 {
                        text-align: center;
                        list-style-type: none;
                        margin-top: 20px;
                    }

                    .nametxt li {
                        float: left;
                        width: 80px;
                        height: 35px;
                        line-height: 35px;
                        display: inline;
                        list-style-type: none;
                        font-size: 20px;
                        border: 1px solid #e2e2e2;
                        margin: 2px;
                    }

                    .nametxt2 li {
                        float: left;
                        width: 160px;
                        height: 35px;
                        line-height: 35px;
                        display: inline;
                        list-style-type: none;
                        font-size: 16px;
                        border: 1px solid #e2e2e2;
                        margin: 2px;
                    }
                    .nametxt3 li {
                        float: left;
                        padding: 1px 10px 1px 10px;
                        height: 35px;
                        line-height: 35px;
                        display: inline;
                        list-style-type: none;
                        font-size: 16px;
                        border: 1px solid #e2e2e2;
                        margin: 2px;
                    }

                    .nametxt,.nametxt2,.nametxt3 li:hover {
                        background-color: #f2f2f2;
                    }

                    .layui-icon {
                        cursor: pointer;
                    }
                </style>
                <div class="layui-tab-content ibox-content">
                    <!--单字 START-->
                    <div class="layui-tab-item <if condition='$tab eq 1'>layui-show</if>">
                        <!--<div class="layui-inline">-->
                        <!--<input type="text" class="layui-input" placeholder="搜索关键字" id="search1">-->
                        <!--</div>-->
                        <!--<div class="layui-inline">-->
                        <!--<button class="layui-btn layui-btn-small" id="c-search-btn">搜索</button>-->
                        <!--</div>-->
                        <div style="width: 100%">
                            <ul class="nametxt" id="nametxt1">
                            </ul>
                            <div style="clear: both"></div>

                        </div>
                        <div id="page1"></div>
                    </div>
                    <!--单字 END-->
                    <!--双字 START-->
                    <div class="layui-tab-item <if condition='$tab eq 2'>layui-show</if>">
                        <div class="layui-inline">
                            <input type="text" class="layui-input" placeholder="搜索关键字" id="search2">
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-small" id="search2-btn">搜索</button>
                        </div>
                        <div style="width: 100%">
                            <ul class="nametxt2" id="nametxt2">
                            </ul>
                            <div style="clear: both"></div>
                        </div>
                        <div id="page2"></div>
                    </div>
                    <!--双字 END-->
                    <!--其他 START-->
                    <div class="layui-tab-item <if condition='$tab eq 3'>layui-show</if>">
                        <div class="layui-inline">
                            <input type="text" class="layui-input" placeholder="搜索关键字" id="search3">
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-small" id="search3-btn">搜索</button>
                        </div>
                        <div style="width: 100%">
                            <ul class="nametxt3" id="nametxt3">
                            </ul>
                            <div style="clear: both"></div>
                        </div>
                        <div id="page3"></div>

                    </div>
                    <!--其他 END-->
                </div>
            </div>
        </div>
    </div>
</div>
<block name="include">
    <include file="Public:footer"/>
</block>
<script>
    layui.use('element', function () {
        var element = layui.element;

    });
    layui.use(['laypage', 'layer'], function () {
        var laypage = layui.laypage
            , layer = layui.layer;
        laypage.render({
            elem: 'page1',
            count: {$count1},
            limits: [100, 200, 300],
            limit: 100,
            layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
            jump: function (obj) {
                layui.use(['jquery', 'layer'], function () {
                    var $ = layui.$
                        , layer = layui.layer;
                    $.ajax({
                        url: "{:U('Nametxt/dataGet')}",
                        data: {
                            type: 1,
                            page: obj.curr,
                            page_count: obj.limit,
//                            search: $("#search1").val()
                        },
                        dataType: 'json',
                        type: 'post',
                        success: function (data) {
                            str = '';
                            for (var i = 0; i < data.length; i++) {
                                str += '<li>' +
                                    data[i].txt +
                                    '&nbsp;&nbsp;&nbsp;' +
                                    '<i class="layui-icon" style="font-size: 18px;color: red;" onclick="removetxt(' + data[i].id + ',1)">&#xe640;</i>' +
                                    '</li>';
                            }
                            $('#nametxt1').html(str);
                        }
                    })
                })
            }
        })
    });
    //    双字列表
    layui.use(['jquery', 'layer'], function () {
        var $ = layui.$
            , layer = layui.layer;
        $('#search2-btn').click(function () {
            ajaxGet2();
        })
    });
    ajaxGet2();

    function ajaxGet2() {
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.ajax({
                url: "{:U('Nametxt/dataCount')}",
                data: {
                    type: 2,
                    search: $("#search2").val()
                },
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    layui.use(['laypage', 'layer'], function () {
                        var laypage = layui.laypage
                            , layer = layui.layer;
                        laypage.render({
                            elem: 'page2',
                            count: data.count,
                            limits: [100, 200, 300],
                            limit: 100,
                            layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
                            jump: function (obj) {
                                layui.use(['jquery', 'layer'], function () {
                                    var $ = layui.$
                                        , layer = layui.layer;
                                    $.ajax({
                                        url: "{:U('Nametxt/dataGet')}",
                                        data: {
                                            type: 2,
                                            page: obj.curr,
                                            page_count: obj.limit,
                                            search: $("#search2").val()
                                        },
                                        dataType: 'json',
                                        type: 'post',
                                        success: function (data) {
                                            str = '';
                                            for (var i = 0; i < data.length; i++) {
                                                str += '<li>' +
                                                    '<span class="layui-badge layui-bg-blue">' + data[i].hits + '</span>&nbsp;' +
                                                    data[i].txt +
                                                    '&nbsp;&nbsp;' +
                                                    '<i class="layui-icon" style="font-size: 18px;color: green;" onclick="addHits(' + data[i].id + ',this)">&#xe6c6;</i>&nbsp;' +
                                                    '<i class="layui-icon" style="font-size: 18px;color: #FF5722;" onclick="decHits(' + data[i].id + ',this)">&#xe6c5;</i>&nbsp;' +
                                                    '<i class="layui-icon" style="font-size: 18px;color: red;" onclick="removetxt(' + data[i].id + ',2)">&#xe640;</i>' +
                                                    '</li>';
                                            }
                                            $('#nametxt2').html(str);
                                        }
                                    })
                                })
                            }
                        })
                    });
                }
            });
        })
    }

    //    其他列表
    layui.use(['jquery', 'layer'], function () {
        var $ = layui.$
            , layer = layui.layer;
        $('#search3-btn').click(function () {
            ajaxGet3();
        })
    });
    ajaxGet3();

    function ajaxGet3() {
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.ajax({
                url: "{:U('Nametxt/dataCount')}",
                data: {
                    type: 3,
                    search: $("#search3").val()
                },
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    layui.use(['laypage', 'layer'], function () {
                        var laypage = layui.laypage
                            , layer = layui.layer;
                        laypage.render({
                            elem: 'page3',
                            count: data.count,
                            limits: [100, 200, 300],
                            limit: 100,
                            layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
                            jump: function (obj) {
                                layui.use(['jquery', 'layer'], function () {
                                    var $ = layui.$
                                        , layer = layui.layer;
                                    $.ajax({
                                        url: "{:U('Nametxt/dataGet')}",
                                        data: {
                                            type: 3,
                                            page: obj.curr,
                                            page_count: obj.limit,
                                            search: $("#search3").val()
                                        },
                                        dataType: 'json',
                                        type: 'post',
                                        success: function (data) {
                                            str = '';
                                            for (var i = 0; i < data.length; i++) {
                                                str += '<li>' +
                                                    '<span class="layui-badge layui-bg-blue">' + data[i].hits + '</span>&nbsp;' +
                                                    data[i].txt +
                                                    '&nbsp;&nbsp;' +
                                                    '<i class="layui-icon" style="font-size: 18px;color: green;" onclick="addHits(' + data[i].id + ',this)">&#xe6c6;</i>&nbsp;' +
                                                    '<i class="layui-icon" style="font-size: 18px;color: #FF5722;" onclick="decHits(' + data[i].id + ',this)">&#xe6c5;</i>&nbsp;' +
                                                    '<i class="layui-icon" style="font-size: 18px;color: red;" onclick="removetxt(' + data[i].id + ',3)">&#xe640;</i>' +
                                                    '</li>';
                                            }
                                            $('#nametxt3').html(str);
                                        }
                                    })
                                })
                            }
                        })
                    });
                }
            });
        })
    }

    //删除字
    function removetxt(id, type) {

        layer.confirm("是否删除", {
            icon: 2,
            btn: ['确定', '取消']
        }, function () {
            layui.use(['jquery', 'layer'], function () {
                var $ = layui.$
                    , layer = layui.layer;
                $.ajax({
                    url: '{:U("Nametxt/delTxt")}',
                    data: {'id': id},
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        if (data.status == 1) {
                            layer.confirm('删除成功', {
                                icon: 1,
                                btn: ['确定']
                            }, function () {
                                window.location.href = '/admin.php/Nametxt/index.html?tab=' + type;
                            });
                        } else {
                            layer.confirm('删除失败', {
                                icon: 1,
                                btn: ['确定']
                            })
                        }
                    }
                })
            });
        });

    }

    //    新增字
    layui.use(['jquery', 'layer'], function () {
        var $ = layui.$
            , layer = layui.layer;
        $('#txtAdd').click(function () {
            var value = $('#txt').val();
            if (value.trim() != '' && value != null) {
                $.ajax({
                    url: '{:U("Nametxt/txtAdd")}',
                    data: {'txt': value},
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        if (data.status == 1) {
                            layer.confirm('添加成功', {
                                icon: 1,
                                btn: ['确定']
                            }, function () {
                                $('#txt').val('');
                                window.location.reload();
                            });
                        } else {
                            layer.confirm('添加失败', {
                                icon: 1,
                                btn: ['确定']
                            })
                        }
                    }
                })
            }
        })
    });

    function addHits(id, obj) {
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.ajax({
                url: '{:U("Nametxt/addHits")}',
                data: {'id': id},
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    if (data.status == 1) {
                        obj.parentNode.children[0].textContent = ++obj.parentNode.children[0].textContent;
                    } else {
                        layer.confirm('提高热度失败', {
                            icon: 1,
                            btn: ['确定']
                        })
                    }
                }
            })
        });
    }

    function decHits(id, obj) {
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.ajax({
                url: '{:U("Nametxt/decHits")}',
                data: {'id': id},
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    if (data.status == 1) {
                        obj.parentNode.children[0].textContent = --obj.parentNode.children[0].textContent;
                    } else {
                        layer.confirm('降低热度失败', {
                            icon: 1,
                            btn: ['确定']
                        })
                    }
                }
            })
        });
    }
</script>
</body>
</html>
